package cn.lili.modules.union.serviceimpl;

import cn.lili.common.utils.StringUtils;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.member.entity.dos.UnionLog;
import cn.lili.modules.union.mapper.UnionLogMapper;
import cn.lili.modules.union.service.UnionLogService;
import cn.lili.mybatis.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UnionLogServiceImpl extends ServiceImpl<UnionLogMapper, UnionLog> implements UnionLogService {

    /**
     * 分页查询工会日志
     * @param unionLog
     * @param pageVO
     * @return
     */
    @Override
    public Page<UnionLog> getByPage (UnionLog unionLog, PageVO pageVO) {
        LambdaQueryWrapper<UnionLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotEmpty(unionLog.getUnionId()), UnionLog::getUnionId, unionLog.getUnionId());
        queryWrapper.orderByDesc(UnionLog::getCreateTime);
        return this.page(PageUtil.initPage(pageVO), queryWrapper);
    }

    /**
     * 记录日志
     * @param unionLog
     * @return
     */
    @Override
    public Boolean addUnionLog (UnionLog unionLog) {
        return this.save(unionLog);
    }

    /**
     * 批量日志
     * @param unionLogList
     */
    @Override
    @Transactional
    @ShardingTransactionType(TransactionType.BASE)
    public void batchAddUnionLog (List<UnionLog> unionLogList) {
        this.saveBatch(unionLogList);
    }
}
